package com.whj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whj.entity.Loan;
import com.whj.mapper.LoanDao;
import com.whj.service.LoanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LoanServiceImpl implements LoanService {
    @Autowired
    private LoanDao loanDao;
    @Override
    public void addLoan(Loan loan) {
        loan.setId( null);
        loan.setStatus(0);
        loan.setCreateTime(new Date());
        loanDao.insert(loan);
    }

    @Override
    public List<Loan> selectList() {
        return loanDao.selectList(null);
    }

    @Override
    public void update(Integer id, Integer status) {
        Loan loan=new Loan();
        loan.setId(id);
        loan.setStatus(status);
        loanDao.updateById(loan);
    }

    @Override
    public List<Loan> selectById(Integer id) {
        QueryWrapper<Loan> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",id);
        return loanDao.selectList(queryWrapper);
    }

    @Override
    public List<Loan> selectBysta(int i) {
        QueryWrapper<Loan> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",i);
        return loanDao.selectList(queryWrapper);
    }
}
